package com.leapp.sk.viewdelegate.personal

import android.app.Activity
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.widget.ListView
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.bean.ClassDetialDataEntity
import com.leapp.sk.bean.ContanctListEntity
import com.leapp.sk.ui.adapter.ContanctAdapter

/**
 * 联系人
 * @author  chaohaipeng  on 2018/8/21.
 */
class ContanctDelegate:BaseAppDelegate(){
    /**
     * 适配器
     */
    var contanctAdapter:ContanctAdapter?=null

    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_contanct
    }

    /**
     * 初始化适配器
     */
    fun initAdapter(context: Activity, mlist: List<ClassDetialDataEntity>){
        val lv_ac_contanct = getView<ListView>(R.id.lv_ac_contanct)
         contanctAdapter = ContanctAdapter(context, mlist)
        lv_ac_contanct.adapter=contanctAdapter
    }

    /**
     * 刷新适配器
     */
    fun notifyAdapter(){
        contanctAdapter?.notifyDataSetChanged()
    }

    /**
     * 设置标题栏
     */
    fun setTitle(title:String?){
        val jtb_as_setting= getView<SKTopBar>(R.id.jtb_ac_contanct)
        if (!TextUtils.isEmpty(title)){
            jtb_as_setting.setTitle(title)
        }
        setEvent(jtb_as_setting)
    }

    /**
     * 设置设置事件
     */
    fun setEvent(topBar: SKTopBar){
        topBar?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<AppCompatActivity>().finish()

            }
            override fun rightOnClick() {
            }

        })
    }
}